package com.findMoneyGame.pages.game {
	import flash.events.MouseEvent;
	import flash.events.Event;

	import com.findMoneyGame.pages.ClosablePage;
	import com.findMoneyGame.pages.game.*;
	import com.findMoneyGame.pages.game.controllers.*;
	import com.findMoneyGame.pages.game.states.*;
	import com.findMoneyGame.models.User;
	import com.findMoneyGame.models.GameLevel;

	public class GameLevelPage extends ClosablePage {
		public static const NEED_MORE_MONEY : String = "needMoreMoney";
		public static const LEVEL_COMPLETE : String = "levelComplete";
		public static const START = 'start';
		public static const STOP = 'stop';

		
		private var _gameLevel : GameLevel;
		private var _gameImage : GameImage;


		public function get imageWidth  () { return width * 1.07; }
		public function get imageHeight () { return height * 1.01; }
		public function get gameLevel () : GameLevel { return _gameLevel; }
		public function set gameLevel (value : GameLevel) { _gameLevel = value; }
		public function get gameImage () : GameImage { return _gameImage; }
		public function set gameImage (value : GameImage) { _gameImage = value; }
		public function get user () : User { return User.getInst(); }


		public function GameLevelPage (gameLevel : GameLevel = null) {
			closeButton.addEventListener(MouseEvent.CLICK, closeBtnEventHandler);
			this._gameLevel = gameLevel;
		}
		public function startGame () { dispatchEvent(new Event(START)); }

		public function stopGame () { dispatchEvent(new Event(STOP)); }
		
		public function levelComplete () {
			var confirmDialog = new LevelCompleteConfirmDialog();
			confirmDialog.addEventListener(
				LevelCompleteConfirmDialog.CONFIRMED, 
				function (event : Event) {
					removeChild(confirmDialog);
					dispatchEvent(new Event(GameLevelPage.LEVEL_COMPLETE));
				}
			);
			confirmDialog.addEventListener(
				LevelCompleteConfirmDialog.HOME, 
				function (e : Event) {
					removeChild(confirmDialog);
					dispatchEvent(new Event(ClosablePage.CLOSE_EVENT));
				}
			);
			confirmDialog.x = 100;
			confirmDialog.y = 100;
			user.addMoney(_gameLevel.data.reward);
			user.incLevel();
			addChild(confirmDialog);
		}
	}
}